<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class News extends CI_Controller {

    	public function __construct(){

            parent::__construct();
            $this->load->helper('url');
        }

        public function index(){
            $data['page']= "news_add";
            $this->load->view('admin/dashboard', $data);
        }

        public function submit(){
          $this->load->model('News_model');
            $news_title     = $this->input->post('news_title');
            $category       = $this->input->post('category');
            $location       = $this->input->post('location');
            $featured       = $this->input->post('featured');
            $caption        = $this->input->post('caption');
            $content        = $this->input->post('content');
            $posted_on      = date("d-m-Y");
    
            if($news_title!="" || $category!="" ||  $location!="" || $content!="" )
            {
                if( $this->News_model->news_post($news_title,$category,$location,$featured,$caption,$content,$posted_on))
                    //echo "news posted successfully";
                  redirect ("admin/backend");
                else
                    echo "news posting falied";
            }
        }

        public function edit($id){
            $this->load->model("News_model");          
            $data['news_edit'] =$this->News_model->news_select($id);
         
            $data['page']= "news_edit";
            $this->load->view('admin/dashboard', $data);
        }

        public function delete($id){
            $this->load->model("News_model");
            if($this->News_model->delete($id))
                //echo "delete success";
                    redirect ("admin/backend");
            else
                echo "delete failed";
        }
//
//        public function update(){
//          $this->load->model('News_model');
//            $news_title     = $this->input->post('news_title');
//            $category       = $this->input->post('category');
//            $location       = $this->input->post('location');
//            $featured       = $this->input->post('featured');
//            $caption        = $this->input->post('caption');
//            $content        = $this->input->post('content');
//            $posted_on      = date("d-m-Y");
//
//            if($news_title!="" || $category!="" ||  $location!="" || $content!="" )
//            {
//                if( $this->News_model->news_post($news_title,$category,$location,$featured,$caption,$content,$posted_on))
//                    echo "news posted successfully";
//                  //redirect (site_url("admin/backend"));
//                else
//                    echo "news posting falied";
//            }
}